package sdk.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import dao.RewAndPunDAO;
import dao.impl.EmpDAOImpl;
import dao.impl.RewAndPunDAOImpl;
import dao.impl.RewAndPunTypeDAOImpl;

import model.Emp;
import model.RewAndPun;
import model.RewAndPunType;
import util.Page;

public class RewAndPunManager {
	RewAndPunDAO rad = new RewAndPunDAOImpl();
	public Page<RewAndPun>getAll(int pageNo,int pageSize){
		return rad.getAll(pageNo, pageSize);
	}
	
	public Page<RewAndPun>getByEmpId(int pageNo,int pageSize,int empid){
		return rad.getByEmpId(pageNo, pageSize, empid);
	}
	
	public Page<RewAndPun>getByRewAndPunType(int pageNo,int pageSize,RewAndPunType rewAndPunType){
		return rad.getByRewAndPunType(pageNo, pageSize, rewAndPunType);
	}

	public Page<RewAndPun>getByTime(int pageNo,int pageSize,Date starttime,Date endtime){
		
		return rad.getByTime(pageNo, pageSize, starttime, endtime);
	}
	
	public Page<RewAndPun>getByContent(int pageNo,int pageSize,String content){
		return rad.getByContent(pageNo, pageSize, content);
	}

	public boolean add(RewAndPun rewAndPun){
		return rad.add(rewAndPun);
	}
	
	public boolean update(RewAndPun rewAndPun){
		return rad.update(rewAndPun);
	}
	
	public boolean deleteById(int id){
		return rad.deleteById(id);
	}

	public boolean deleteByEmpId(int empid){
		return rad.deleteByEmpId(empid);
	}
	
	public boolean addRewAndPun(String title,String empno, int rewanpubtype,String date,String content,double money)
	{
		RewAndPun re=new RewAndPun ();
		re.setTitle(title);
		Emp e=new Emp();
		e.setId(new EmpDAOImpl().getIDByEmpno(empno));
		re.setEmp(e);
		RewAndPunType rewAndPunType=new RewAndPunType();
		rewAndPunType.setId(rewanpubtype);
		re.setRewAndPunType(rewAndPunType);
		try {
			re.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(date));
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		re.setContent(content);
		re.setMoney(money);
		return rad.add(re);
	}
	
	public Emp getEmpByEmpno(String empno)
	{
		
		return new EmpDAOImpl().getEmpById(new EmpDAOImpl().getIDByEmpno(empno));
	}
	
	public List<RewAndPunType> getAllRewAndPunType()
	{
		return new RewAndPunTypeDAOImpl().getAll();
	}
	
	public RewAndPun getRewAndPunById(int id)
	{
		return new RewAndPunDAOImpl().getById(id);
	}
	
	public boolean updateRewAndPun(int reid,String edittitle,int editAndPunType,String content,double editmoney)
	{
		RewAndPun re=new RewAndPun ();
		re.setId(reid);
		re.setTitle(edittitle);
		RewAndPunType rt=new RewAndPunType();
		rt.setId(editAndPunType);
		
		re.setRewAndPunType(rt);
		re.setContent(edittitle);
		re.setMoney(editmoney);
		return new RewAndPunDAOImpl().updateRewAnd(re);
	}
	
	public Page<RewAndPun> getAll(int pageNo, int pageSize ,String name) {
		
		return new RewAndPunDAOImpl().getAll(pageNo, pageSize, name);
	}
}
